<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="sealte.hvpms.pojo.Admin,sealte.hvpms.dao.AdminDAO,sealte.hvpms.dao.impl.AdminDAOImpl,java.util.List,java.util.Iterator" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>网上投票管理系统</title>
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link type="text/css" rel="stylesheet" href="css/admin_management.jsp.css" />
<script src="js/jquery-1.4.4.min.js" type="text/javascript"></script>
<script language=javascript>
function validate(){
	var an = $('#adminName').val();
	var form = $('#addForm');
	var reg = /^\s+|\s+$/g;
	an = an.replace(reg,"");
	if(an!=""){
		form.submit();
	}else{
		alert("账号不能为空！！");
	}
}
function resetPassword(id){
	if(confirm("确定重置该管理员的密码？")==true){
		$.post("AdminResetPassword",{id:id},function callback(data){
			alert(data);
			window.location.href = '<%=basePath%>hvpms_admin/admin_management.jsp';
		});
	}
}
function deleteAdmin(id){
	if(confirm("确定删除该管理员的所有信息？")==true){
		$.post("AdminDeleteAC",{id:id},function callback(data){
			alert(data);
			window.location.href = '<%=basePath%>hvpms_admin/admin_management.jsp';
		});
	}
}
function sbar(st, col) {
	st.style.backgroundColor = '#EAF4FE';
}
function cbar(st) {
	st.style.backgroundColor = '';
}
</script>
</head>
<body>
<%
	Admin admin = (Admin)session.getAttribute("admin");
	if(admin!=null&&admin.getLevel().equals("a")){
%>
<div id="num2">
	<h2><img src="images/group_gear.png">&nbsp;管理员管理--维护</h2>
</div>

<div id="num3">
	<form action="AdminAdd" method="POST" id="addForm">
	<table id="topTable">
	<tr>
		<th width="6%" align="right">账号</th>
		<td width="15%" align="left"><input type="text" name="admin_name" id="adminName"></td>
		<th width="6%" align="right">密码</th>
		<td width="20%" align="left"><input type="text" name="admin_password" value="666666"/></td>
		<td><input type="button" value="添加" onclick="validate()"/></td>
	</tr>
	</table>
	</form>
</div>

<div id="num1">
	<table id="showTable">
		<tr>
			<th width="6%">序号</th><th>账号</th><th width="20%">权限级别</th><th width="30%">操作</th>
		</tr>
<%
	AdminDAO ab = new AdminDAOImpl();
	List<Admin> all = ab.getAll();
	if(all.size()>1){
		Iterator<Admin> iter = all.iterator();
		int i = 0;
		while(iter.hasNext()){
			Admin one = iter.next();
			String level = (one.getLevel().equals("a"))?"超级管理员":"普通管理员";
			if(one.getId()!=admin.getId()){		
%>
		<tr onmouseover=sbar(this) onmouseout=cbar(this)>
		<td><%=(++i) %></td>
		<td><%=one.getName() %></td>
		<td><%=level %></td>
		<td>
			<a href="javascript:resetPassword(<%=one.getId() %>)">重置密码</a>
			&nbsp;|&nbsp;
			<a href="AdminChangeLevel?id=<%=one.getId() %>&level=<%=one.getLevel() %>">修改权限</a>
			&nbsp;|&nbsp;
			<a href="javascript:deleteAdmin(<%=one.getId() %>)">删除账号</a>
		</td>
		</tr>	
<%
			}
		}
	}else{
%>
		<tr><td colspan=4>暂时无任何数据</td></tr>
<%
	}
%>		
	</table>
</div>
<span>
	<%
		String message_addNew = (String)request.getAttribute("message_addNew");
		String message_acl = (String)request.getAttribute("message_acl");
		if(message_addNew!=null && !message_addNew.equals("")){
			out.println("["+message_addNew+"]");
		}
		if(message_acl!=null&&!message_acl.equals("")){
			out.println("["+message_acl+"]");
		}
	%>
</span>
<%	
	}else{
		out.println("谢绝跨路径访问！");
	}
%>
</body>
</html>